/* $Header: ax_cmds.c,v 2.2 01/10/02 10:29:11 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME: ax_cmds.c                                              */
/* ============                                                        */
/*                                                                     */
/* Author:  Bob Cook                                                   */
/*                                                                     */
/* MODULE PURPOSE: This module will handle the aux commands.           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

/*
 */

/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>

#include <error.h>

#include <mio.h>
#include <cmd_set.h>
#include <cmdproc.h>
#include <method.h>
#include <hostutil.h>
#include <cmd_tbls.h>
#include <ramps.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <zone_config.h>
#include <zone_status.h>
#include <status.h>
#include <zone_ui.h>


/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/



/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/

/*****************************/
/*   LOCAL DEFINES           */
/*****************************/

/* if BC_DEBUG is defined debug buffers are created and statics become global */
#define BC_DEBUG

/* when debugging make variables global for emulator testing */
#ifdef BC_DEBUG
#   define SCOPE
#else
#   define  SCOPE  static
#endif


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/



/*****************************/
/*   MACROS                  */
/*****************************/



/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/



/***********************************************************************/
/* FUNCTION: DoAXEO                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Echo command.                                              */
/*                                                                     */
/* RETURNED VALUE: length of response string                           */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 DoAXEO(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
U_INT16 len;

   len = 0;

   if (p_cmd->parmv[0] == 1)
   {
      len = PutAsciiParam((BIT8 *)"\"", p_resp_parm);
      len += PutAsciiParam((BIT8 *)&(p_cmd->parms[p_cmd->parmv[1]]),
                                     p_resp_parm+len);
      len += PutAsciiParam((BIT8 *)"\"", p_resp_parm+len);
      return len;
   }
   else
   {
      CmdErrorHandler(p_cmd,1,INVALID_PARAM);
      return NO_RESPONSE;
   }
}

/***********************************************************************/
/* END FUNCTION: DoAXEO                                                */
/***********************************************************************/




/***********************************************************************/
/* FUNCTION: DoAXST                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: handles A1 and A2 thermal status.                          */
/*                                                                     */
/* RETURNED VALUE: length of response                                  */
/*                                                                     */
/***********************************************************************/
INT16 DoAXST(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
   INT16       parm_len;
   pZONE_TABLE pzone;
/*-----changed by wangwei---------------*/
printf("call DoAXST\n");
/*
   if( p_cmd->dsap.char_dsap[1] == '1')
   {
      pzone = pAUX_1_TEMP;
   }
   else
   {
      pzone = pAUX_2_TEMP;
   }

   parm_len  = PutIntParam( (INT32)GetTempStatus(pzone), p_resp_parm, 0 );
   parm_len += PutAsciiParam((BIT8 *)",",p_resp_parm+parm_len);
   parm_len += PutIntParam( GetTempSetpt(pzone), p_resp_parm+parm_len, 0 );
   parm_len += PutAsciiParam((BIT8 *)",",p_resp_parm+parm_len);
   parm_len += PutIntParam( GetTempActual(pzone), p_resp_parm+parm_len, 0 );
*/
/*----------end change ---------------*/
   return  parm_len;
}
/***********************************************************************/
/* END FUNCTION: DoAXST                                                */
/***********************************************************************/

/***********************************************************************/
/* FUNCTION: AXOpcodes                                                 */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calls routines needed to implement the AX commands.        */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 AXOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len)
{
INT16           parm_len;

   (void) max_resp_len;

   parm_len = NO_RESPONSE;

   switch( p_cmd->opcode.int_op )
   {

/*-----changed by wangwei---------------*/
/*
      case  MAKEINT('C','R'):
        parm_len = (p_cmd->dsap.char_dsap[1] == '1') ?
          DoCmd(p_cmd,p_resp_parm,&mA1CR) : DoCmd(p_cmd,p_resp_parm,&mA2CR);
        break;

      case MAKEINT( 'T', 'I' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '1': parm_len = DoCmd(p_cmd,p_resp_parm,&mA1TI); break;
             case '2': parm_len = DoCmd(p_cmd,p_resp_parm,&mA2TI); break;
        }
        break;

      case MAKEINT( 'T', 'Z' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '1': parm_len = DoCmd(p_cmd,p_resp_parm,&mA1TZ); break;
             case '2': parm_len = DoCmd(p_cmd,p_resp_parm,&mA2TZ); break;
        }
        break;
      case MAKEINT( 'T', 'R' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '1': parm_len = DoCmd(p_cmd,p_resp_parm,&mA1TR); break;
             case '2': parm_len = DoCmd(p_cmd,p_resp_parm,&mA2TR); break;
        }
        break;
      case MAKEINT( 'T', 'P' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '1': parm_len = DoCmd(p_cmd,p_resp_parm,&mA1TP); break;
             case '2': parm_len = DoCmd(p_cmd,p_resp_parm,&mA2TP); break;
        }
        break;
*/
      case MAKEINT( 'P', 'R' ):
/*------------changed by wangwei--------------------*/
        mLog("AXOpcodes deal PR cmd\n");
        switch( p_cmd->dsap.char_dsap[1] )
        {
/*--------------end change--------------------------*/
             case '3': parm_len = DoCmd(p_cmd,p_resp_parm,&mA3PR); break;
             case '4': parm_len = DoCmd(p_cmd,p_resp_parm,&mA4PR); break;
             case '5': parm_len = DoCmd(p_cmd,p_resp_parm,&mA5PR); break;
        }
        break;

      case MAKEINT( 'S', 'T' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
         case '1':
         case '2': parm_len = DoAXST( p_cmd, p_resp_parm); break;
         case '3': parm_len = DoStatus(p_cmd,p_resp_parm,&mA3ST); break;
         case '4': parm_len = DoStatus(p_cmd,p_resp_parm,&mA4ST); break;
         case '5': parm_len = DoStatus(p_cmd,p_resp_parm,&mA5ST); break;
        }
        break;

      case MAKEINT( 'P', 'Z' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '3': parm_len = DoCmdWithResponse(p_cmd,p_resp_parm,&mA3PZ); break;
             case '4': parm_len = DoCmdWithResponse(p_cmd,p_resp_parm,&mA4PZ); break;
             case '5': parm_len = DoCmdWithResponse(p_cmd,p_resp_parm,&mA5PZ); break;
        }
        break;
      case MAKEINT( 'F', 'Z' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '3':
             case '4':
             case '5': parm_len = DoCmdWithResponse(p_cmd,p_resp_parm,&mAXFZ); break;
        }
        break;

      case MAKEINT( 'P', 'V' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '3': parm_len = DoCmdWithResponse(p_cmd,p_resp_parm,&mA3PV); break;
             case '4': parm_len = DoCmdWithResponse(p_cmd,p_resp_parm,&mA4PV); break;
             case '5': parm_len = DoCmdWithResponse(p_cmd,p_resp_parm,&mA5PV); break;
        }
        break;

      case MAKEINT( 'L', 'S' ):
         parm_len = DoStatus(p_cmd,p_resp_parm,&mAXLS);
         break;

      case MAKEINT( 'L', 'X' ):
         parm_len = DoCmdWithResponse(p_cmd,p_resp_parm,&mAXLX);
         break;

      case MAKEINT( 'P', 'I' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '3': parm_len = DoCmd(p_cmd,p_resp_parm,&mA3PI); break;
             case '4': parm_len = DoCmd(p_cmd,p_resp_parm,&mA4PI); break;
             case '5': parm_len = DoCmd(p_cmd,p_resp_parm,&mA5PI); break;
        }
        break;

      case MAKEINT( 'C', 'F' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '3': parm_len = DoCmd(p_cmd,p_resp_parm,&mA3CF); break;
             case '4': parm_len = DoCmd(p_cmd,p_resp_parm,&mA4CF); break;
             case '5': parm_len = DoCmd(p_cmd,p_resp_parm,&mA5CF); break;
        }
        break;
/*
      case MAKEINT( 'C', 'W' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '1': parm_len = DoCmd(p_cmd,p_resp_parm,&mA1CW); break;
             case '2': parm_len = DoCmd(p_cmd,p_resp_parm,&mA2CW); break;
             case '3': parm_len = DoCmd(p_cmd,p_resp_parm,&mA3CW); break;
             case '4': parm_len = DoCmd(p_cmd,p_resp_parm,&mA4CW); break;
             case '5': parm_len = DoCmd(p_cmd,p_resp_parm,&mA5CW); break;
        }
        break;

      case MAKEINT( 'Z', 'W' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '1': parm_len = DoCmd(p_cmd,p_resp_parm,&mA1ZW); break;
             case '2': parm_len = DoCmd(p_cmd,p_resp_parm,&mA2ZW); break;
        }
        break;

*/
      case MAKEINT( 'N', 'Z' ):
        switch( p_cmd->dsap.char_dsap[1] )
        {
             case '3': parm_len = DoCmd(p_cmd,p_resp_parm,&mA3NZ); break;
             case '4': parm_len = DoCmd(p_cmd,p_resp_parm,&mA4NZ); break;
             case '5': parm_len = DoCmd(p_cmd,p_resp_parm,&mA5NZ); break;
        }
        break;
      case  MAKEINT('E','O'):
        parm_len = DoAXEO(p_cmd,p_resp_parm);
        break;

      default:
         parm_len = NO_RESPONSE;
         CmdErrorHandler(p_cmd,0,INVALID_OP);
         break;
   }
/*----------end change---------------*/
   return parm_len;
}


/***********************************************************************/
/* END FUNCTION: AXOpcodes                                             */
/***********************************************************************/



/***********************************************************************/
/* FUNCTION: AX_Cmds                                                   */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calls function which executes a command if one is          */
/*          available on the command queue.                            */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

void AX_Cmds(void)
{
   ExecCmds(&AX_Cmd_Q,AXOpcodes);
}

/***********************************************************************/
/* END FUNCTION: AX_Cmds                                               */
/***********************************************************************/

